home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / linksrc < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  9.6 KB

  1. From: joe@hanauma.STANFORD.EDU (Joe Dellinger)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i040: linksrc - ease source maintenance over heterogenous NFS
  4. Message-ID: <7175@ncoast.UUCP>
  5. Date: 3 Feb 88 02:03:39 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 40
  9. Submitted-By: "Joe Dellinger" <joe@hanauma.STANFORD.EDU>
  10. Archive-Name: linksrc
  11.  
  12. #! /bin/sh
  13. # This is a shell archive, meaning:
  14. # 1. Remove everything above the #! /bin/sh line.
  15. # 2. Save the resulting text in a file.
  16. # 3. Execute the file with /bin/sh (not csh) to create the files:
  17. #    README
  18. #    binary.c
  19. #    corr
  20. #    linksrc
  21. # This archive created: Wed Jan 27 23:44:03 1988
  22. export PATH; PATH=/bin:$PATH
  23. if test -f 'README'
  24. then
  25.     echo shar: will not over-write existing file "'README'"
  26. else
  27. sed 's/^J //' << \SHAR_EOF > 'README'
  28. J Linksrc:
  29. J     This is our solution to the problem of many UNIX machines NFS'd together,
  30. J sharing the same source code but with incompatible object and executable files.
  31. J The simplest solution is simply to maintain a copy of the source on one of each
  32. J type of machine. This is a bad idea as it invites such problems as divergent
  33. J source, loss of bug fixes, archaic copies of files surviving to cause trouble,
  34. J etc, etc.
  35. J     Another solution would be to have a "smart" version of Make, one that
  36. J knows about different kinds of machines, keeps track of .o and .a files for
  37. J different kinds of machines, etc, etc. This would be nice, but would involve
  38. J first GETTING such a magical smart "make" and then trying to get it to work
  39. J with what you've already got with the least bother. Ug.
  40. J     My solution is inelegant, but simple. One central machine will maintain
  41. J the "master copy" of the "official device-independent source". For each kind
  42. J of machine that you need to separately compile the source on, there will be
  43. J one machine that contains the "shadow copy" of the "official device-independent
  44. J source". Now, we would be back to the problem of having multiple copies of
  45. J the source again, but there's a simple trick. Mount the "master copy" on
  46. J each machine via NFS. Have all the device-independent source files in the
  47. J "shadow copy" be mere symbolic links to the "master copy". The device
  48. J dependent files are not linked.
  49. J     For example, you can have a directory like this:
  50. J On the "master machine", a C-1:
  51. J cd /usr/src/graphics/vplot/util
  52. J ls -l
  53. J total 65
  54. J -rw-rw-r--  1 rick          409 Nov  8 23:06 Makefile
  55. J -rw-rw-r--  1 rick          200 Nov  8 23:06 README
  56. J -rw-rw-r--  1 rick        11419 Jan 27 00:06 plas.c
  57. J -rw-rw-r--  1 rick        24727 Jan 20 23:16 plas.o
  58. J -rw-rw-r--  1 rick        10150 Jan 27 00:06 pldb.c
  59. J -rw-rw-r--  1 rick        14873 Jan 20 23:17 pldb.o
  60. J -rwxrwxr-x  1 rick          564 Nov  8 23:06 tube.example
  61. J The "shadow" version of the same directory on another machine, a Sun 3:
  62. J cd /usr/src/sepsrc/vplot/util
  63. J ls -l
  64. J total 106
  65. J -rw-rw-r--  1 joe           442 Jan 20  1988 Makefile
  66. J lrwxrwxrwx  1 root           36 Jan 27  1988 README -> /husr/src/graphics/vplot/util/README
  67. J -rwxrwxr-x  1 root        40960 Jan 20  1988 plas
  68. J lrwxrwxrwx  1 root           36 Jan 27  1988 plas.c -> /husr/src/graphics/vplot/util/plas.c
  69. J -rw-rw-r--  1 root        11941 Jan 20  1988 plas.o
  70. J -rwxrwxr-x  1 root        40960 Jan 20  1988 pldb
  71. J lrwxrwxrwx  1 root           36 Jan 27  1988 pldb.c -> /husr/src/graphics/vplot/util/pldb.c
  72. J -rw-rw-r--  1 root         8275 Jan 20  1988 pldb.o
  73. J lrwxrwxrwx  1 root           42 Jan 27  1988 tube.example -> /husr/src/graphics/vplot/util/tube.example
  74. J     We thus have 2 copies of the source on 2 different machines.
  75. J "Make" will work on both without conflict, and the machine independent
  76. J files (here the .c's, the README, and tube.example) are guaranteed to not
  77. J diverge. Note that Make looks at the last-modified date of the linked-to file,
  78. J not the link itself. This trick also makes it much easier to avoid redundancy
  79. J when doing source backups.
  80. J ########################################################################
  81. J Now that I've explained the reasoning, here's the program:
  82. J Linksrc is the csh I created to make it easier to set this all up.
  83. J Do
  84. J linksrc master_directory shadow_directory
  85. J It will work through all subdirectories of the master_directory,
  86. J either linking or copying appropriate files to the corresponding
  87. J position in the shadow_directory. 
  88. J Here are the rules:
  89. J If there is already a file in the shadow source directory, or a link
  90. J that points to something that exists, that file will be left alone.
  91. J If the master copy of the file is a
  92. J .o file, .a file, a "special" file, or a non-ASCII file (unless ending in .v),
  93. J nothing will be done.
  94. J If the master copy of the file matches
  95. J the patterns "[mM]ake*", "install*", "param*.h", "site*.h",
  96. J "machdep*", or "mach_dep*", the file will be copied instead of linked.
  97. J Otherwise the shadow copy of the file will be a symbolic link to the
  98. J master copy.
  99. J Whenever a new directory needs to be created, you will be asked whether
  100. J you want it created. If you do not let it create it, then all shadow source
  101. J directories under it will be automatically skipped.
  102. J The file "corr" (you might want to change the name of it, and make it a
  103. J hard path name) should contain a set of "sed" substitutions for changing
  104. J master directory names to shadow directory names. Make sure to list longer
  105. J substitution strings first! I provide a copy of a "corr" file for our
  106. J machine.
  107. J The program "binary" is used to tell whether a file is binary or not.
  108. J I would have used the "file" command, but have discovered that "file"
  109. J commands can say silly things about files on other machines. You will
  110. J need to compile and install the "binary" program.
  111. J You may want to periodically update the links to catch master files that
  112. J have changed names, been newly created, or disappeared. You can do this from
  113. J crontab once a day or so, like thus:
  114. J yes no | linksrc ....
  115. J The "yes" command will always answer "no" when linksrc asks whether it
  116. J should create a new directory.
  117. J #######################################################
  118. J Anyway, hope other people find this trick useful.
  119. J You'll probably want to modify the innards of linksrc a bit to adapt
  120. J it to your local situations. I distribute this strictly as-is. If you
  121. J can't figure out how it works, or you do something stupid to yourself
  122. J with it, tough!
  123. J - Joe Dellinger
  124. J joe@hanauma.stanford.edu
  125. J decvax!hanauma!joe
  126. SHAR_EOF
  127. if test 5479 -ne "`wc -c < 'README'`"
  128. then
  129.     echo shar: error transmitting "'README'" '(should have been 5479 characters)'
  130. fi
  131. fi # end of overwriting check
  132. if test -f 'binary.c'
  133. then
  134.     echo shar: will not over-write existing file "'binary.c'"
  135. else
  136. sed 's/^J //' << \SHAR_EOF > 'binary.c'
  137. J /*
  138. J  * See if a file is Ascii or not.
  139. J  *
  140. J  * Keyword: binary file status
  141. J  */
  142. J #include <stdio.h>
  143. J main()
  144. J {
  145. J int ii, jj, kk;
  146. J kk = 0;
  147. J for (ii=0; ii < 100; ii++)
  148. J {
  149. J if ( (jj = getchar()) == EOF )
  150. J     {
  151. J     break;
  152. J     }
  153. J if (jj == 0 || jj > '~')
  154. J     {
  155. J     kk = 1;
  156. J     break;
  157. J     }
  158. J }
  159. J printf("%d\n",kk);
  160. J }
  161. SHAR_EOF
  162. if test 277 -ne "`wc -c < 'binary.c'`"
  163. then
  164.     echo shar: error transmitting "'binary.c'" '(should have been 277 characters)'
  165. fi
  166. fi # end of overwriting check
  167. if test -f 'corr'
  168. then
  169.     echo shar: will not over-write existing file "'corr'"
  170. else
  171. sed 's/^J //' << \SHAR_EOF > 'corr'
  172. J s+/husr/src/graphics/vplot/filters/otherpens/+/usr/src/sepsrc/vplot/filters/+
  173. J s+/husr/src/graphics/+/usr/src/sepsrc/+
  174. SHAR_EOF
  175. if test 118 -ne "`wc -c < 'corr'`"
  176. then
  177.     echo shar: error transmitting "'corr'" '(should have been 118 characters)'
  178. fi
  179. fi # end of overwriting check
  180. if test -f 'linksrc'
  181. then
  182.     echo shar: will not over-write existing file "'linksrc'"
  183. else
  184. sed 's/^J //' << \SHAR_EOF > 'linksrc'
  185. J #!/bin/csh -f
  186. J #
  187. J # Author - Joe Dellinger
  188. J # Stanford Exploration Project
  189. J # Dept of Geophysics, Stanford University
  190. J # January 27, 1988
  191. J #
  192. J if ( $#argv != 2 ) then
  193. J     echo "Usage: linksrc remote_dir local_dir"
  194. J     exit
  195. J endif
  196. J foreach direct (`find $1 -type d -print`)
  197. J set there = "$direct/"
  198. J set here = `echo $there | sed -f corr`
  199. J set heredir = `echo $here | sed -e 's+/$++'`
  200. J if (-e $heredir) then
  201. J  if (! -w $heredir || ! -d $heredir) then
  202. J   echo "Can't write in $heredir, so skipping it."
  203. J   continue
  204. J  endif
  205. J  echo "Doing directory $heredir"
  206. J else
  207. J  set hereabove = `echo $here | sed -e 's+[^/]*/$++'`
  208. J  set hereabovedir = `echo $hereabove | sed -e 's+/$++'`
  209. J  if (-w $hereabovedir && -d $hereabovedir) then
  210. J   again:
  211. J   echo "Directory $heredir does not exist."
  212. J   echo "Should I create it?"
  213. J   set answer =  $<
  214. J   if ($answer =~ y* ) then
  215. J    echo "OK, I'll create it."
  216. J    mkdir $heredir
  217. J   else if ($answer =~ n* ) then
  218. J    echo "OK, I'll skip it."
  219. J    continue
  220. J   else
  221. J    echo "Answer yes or no, you idiot\!"
  222. J    goto again
  223. J   endif
  224. J   
  225. J  else
  226. J  echo "Can't write in $hereabovedir,"
  227. J  echo "  so I'm forced to skip $heredir"
  228. J  continue
  229. J  endif
  230. J endif
  231. J foreach file (`cd $there; echo *`)
  232. J if ( ! -e $here$file && -f $there$file \
  233. J     && $file !~ *.o && $file !~ *.a \
  234. J     && ("0" == `binary < $there$file` || $file =~ *.v ) ) then
  235. J if ( $file !~ Make* && $file !~ make* \
  236. J     && $file !~ install* && $file !~ param*.h && $file !~ site*.h \
  237. J     && $file !~ machdep* && $file !~ mach_dep* ) then
  238. J rm -f $here$file
  239. J ln -s $there$file $here$file
  240. J echo linked $file
  241. J else
  242. J rm -f $here$file
  243. J cp -p $there$file $here$file
  244. J echo copied $file
  245. J endif
  246. J endif
  247. J end
  248. J end
  249. SHAR_EOF
  250. if test 1608 -ne "`wc -c < 'linksrc'`"
  251. then
  252.     echo shar: error transmitting "'linksrc'" '(should have been 1608 characters)'
  253. fi
  254. chmod +x 'linksrc'
  255. fi # end of overwriting check
  256. #    End of shell archive
  257. exit 0
  258.